#include "grate_test_utils.h"
#include "grate/dfa.h"
#include "grate/util/common.h"

using growth_rate::LexminTrie;
using growth_rate::Backward;
using growth_rate::Forward;

namespace {

TEST(LexminTrieTest, AddAndCheckAcceptance) {
  size_t capacity = 10;
  uint8_t alphabet_size = 3;
  LexminTrie trie(capacity, alphabet_size);
  EXPECT_GT(trie.size(), 0U);

  EXPECT_TRUE(trie.add_lexmin_word("abc"));
  EXPECT_TRUE(trie.add_lexmin_word("aabc"));

  EXPECT_TRUE(trie.accepts_word("ab", Forward));  // ab
  EXPECT_TRUE(trie.accepts_word("bc", Forward));  // bc
  EXPECT_TRUE(trie.accepts_word("c", Backward));  // a
  EXPECT_FALSE(trie.accepts_word("abc", Forward));  // abc
  EXPECT_FALSE(trie.accepts_word("aabc", Forward));  // aabc
  EXPECT_FALSE(trie.accepts_word("acba", Forward));  // acb=abc
  EXPECT_TRUE(trie.accepts_word("aaa", Backward));  // aaa
  EXPECT_FALSE(trie.accepts_word("cabb", Backward));  // bba=aab

  // LexminTrie would overflow now.
  EXPECT_FALSE(trie.add_lexmin_word("aaaaaaabc"));
}

TEST(LexminTrieTest, DumpTest) {
  LexminTrie trie(100, 3);
  EXPECT_EQ("[(-2, -2, -2)]", trie.dump_transitions());
  trie.add_lexmin_word("abc");
  trie.add_lexmin_word("aabc");
  trie.add_lexmin_word("aaa");
  EXPECT_EQ("[(1, -2, -2),\n"
             "(3, 2, -2),\n"
             "(-2, -2, -1),\n"
             "(-1, 4, -2),\n"
             "(-2, -2, -1)]", trie.dump_transitions());
  EXPECT_EQ(5U, trie.size());
}

}  // namespace
